<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="https://www.layuicdn.com/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.min.js"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(['table','form','jquery','layer'], function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        table.render({
            id : 'departmentTable'
            ,elem: '#test'
            ,url:'/firstWeb/employee/queryAll'
            ,title: '用户数据表'
            ,where: {}
            ,cols: [[
                {field:'id', title:'员工编号'}
                ,{field:'part', title:'所在部门' ,templet:function (data) {
                    return data.part.name
                    }}
                ,{field:'loginName', title:'登陆名'}
                ,{field: 'password', title:'登陆密码'}
                ,{field:'img', title:'员工图片'}
                ,{field:'gender', title:'员工性别'}
                ,{field: 'flag', title:'员工级别'}
                ,{field:'admin', title:'员工操作系统级别'}
                ,{field: 'trueName', title:'员工真实姓名'}
                ,{field:'remark', title:'员工备注'}
                ,{field: 'is', title:'员工状态'}
                ,{field: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true // 默认一页十条
            ,limit:5
            ,limits: [1,5,10,20]
        });

        $("#formsubmit").click(function(){
            table.reload('departmentTable',{
                where : data
                ,page: {
                    curr: 1
                }
            })
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

</body>
</html>